package com.yanqu.road.server.cmd.marriage.cross;

import com.yanqu.road.pb.marriage.MarriageProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.CrossMarriageGroupMgr;
import com.yanqu.road.server.manger.marriage.MarriageMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_MARRIAGE_APPLY_CANCEL, desc = "跨服联姻取消")
public class CrossMarriageApplyCancelCmd extends AbstractCommand {

    private String childUid;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MarriageProto.MarriageApplyCancelReqMsg reqMsg = MarriageProto.MarriageApplyCancelReqMsg.parseFrom(packet.getBytes());
        childUid = reqMsg.getChildUid();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(!CrossMarriageGroupMgr.canCrossMarriage(GameServer.getInstance().getServerId())){
            ret = GameErrorCode.E_CROSS_MARRIAGE_NO_OPEN;
            return;
        }
        ret = MarriageMgr.cancelCrossMarriage(player, childUid, false);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(0 != ret) {
            MarriageProto.MarriageApplyCancelRespMsg.Builder respMsg = MarriageProto.MarriageApplyCancelRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_CROSS_MARRIAGE_APPLY_CANCEL, respMsg);
        }
    }
}
